<?php

/**
 * This is the model class for table "dosen".
 *
 * The followings are the available columns in table 'dosen':
 * @property string $NIP
 * @property string $password
 * @property string $firstName
 * @property string $lastName
 * @property string $middleName
 * @property string $title
 * @property string $placeofBirth
 * @property string $dateofBirth
 * @property string $address
 * @property string $phone
 * @property string $email
 *
 * The followings are the available model relations:
 * @property Membimbing[] $membimbings
 * @property Publikasi[] $publikasis
 */
class Dosen extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return Dosen the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'dosen';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('NIP, password, firstName, lastName, title, placeofBirth, dateofBirth, address, phone, email', 'required'),
			array('NIP', 'length', 'max'=>20),
			array('password', 'length', 'max'=>56),
			array('firstName, lastName, title, placeofBirth, address, phone, email', 'length', 'max'=>50),
			array('middleName', 'length', 'max'=>75),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('NIP, password, firstName, lastName, middleName, title, placeofBirth, dateofBirth, address, phone, email', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'membimbings' => array(self::HAS_MANY, 'Membimbing', 'NIP'),
			'publikasis' => array(self::MANY_MANY, 'Publikasi', 'pub_dosen(NIP, ID_Pub)'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'NIP' => 'Nip',
			'password' => 'Password',
			'firstName' => 'First Name',
			'lastName' => 'Last Name',
			'middleName' => 'Middle Name',
			'title' => 'Title',
			'placeofBirth' => 'Placeof Birth',
			'dateofBirth' => 'Dateof Birth',
			'address' => 'Address',
			'phone' => 'Phone',
			'email' => 'Email',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('NIP',$this->NIP,true);
		$criteria->compare('password',$this->password,true);
		$criteria->compare('firstName',$this->firstName,true);
		$criteria->compare('lastName',$this->lastName,true);
		$criteria->compare('middleName',$this->middleName,true);
		$criteria->compare('title',$this->title,true);
		$criteria->compare('placeofBirth',$this->placeofBirth,true);
		$criteria->compare('dateofBirth',$this->dateofBirth,true);
		$criteria->compare('address',$this->address,true);
		$criteria->compare('phone',$this->phone,true);
		$criteria->compare('email',$this->email,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}